package com.niit.galuser.service.impl;

import com.niit.dao.UserDao;
import com.niit.entity.User;
import com.niit.galuser.service.UserService;
import com.niit.utils.SendMsg;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.servlet.http.HttpSession;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private SendMsg sendMsg;

    @Resource
    private UserDao userDao;

    @Override
    public String sendMsg(HttpSession session, String addr) throws MessagingException {
        String code = sendMsg.makeCode();
        session.setAttribute(addr,sendMsg.makeMsg(code));
        sendMsg.sendMsg(addr,sendMsg.makeTitle(), (String) session.getAttribute(addr));
        return code;
    }

    @Override
    public User findUserByMail(String mail) {
        return userDao.queryByEmail(mail);
    }

    @Override
    public int insertUser(User user) {
        return userDao.insert(user);
    }

    @Override
    public User findUserById(int id) {
        return userDao.queryById(id);
    }

    @Override
    public int setInfo(User user) {
        return userDao.update(user);
    }
}
